package org.viva.service.secu;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.viva.core.dao.BaseDAO;
import org.viva.entity.secu.Org;

@Service("orgService")
public class OrgService {

    @Resource
    private BaseDAO<Org> dao;

    public List<Org> getAllMap() {
        List<Org> list = dao.find("from Org order by pid,sort");
        return list;
    }

    public List<Org> getById(Long id) {
        List<Org> list = dao.find("from Org order by pid,sort");
        return list;
    }
    //
    // private void addList(List<Org> list, Set<Org> orgs) {
    // for (Org org : orgs) {
    // list.add(org);
    // if (org.getChildren() != null) addList(list, org.getChildren());
    // }
    // }

    public Org get(long id) {
        return dao.get(Org.class, id);
    }

    public void save(Org org) {
        if (org == null) return;
        if (org.getId() == null) {
            dao.saveOrUpdate(org);
        } else {
            Org o = get(org.getId());
            o.setIconFa(org.getIconFa());
            o.setName(org.getName());
            o.setSname(org.getSname());
            o.setSort(org.getSort());
            o.setStatus(org.getStatus());
            o.setType(org.getType());
        }
    }

    public List<Org> queryByPid(Long pid) {
        List<Org> list = dao.find("From Org where pid = " + pid + " order by pid,sort");
        return list;
    }

}
